home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
C and C++
/
Libraries
/
usr (gcc 1.37 libs)
/
mac
/
pipe.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-12-08
|
1KB
|
53 lines
#include <OSUtils.h>
#include <Events.h>
#include <EPPC.h>
#include <Processes.h>
#include <stdio.h>
#include <fcntl.h>
#include "crtlocal.h"
static OSErr waitforcompletion(volatile OSErr *err)
{
while (*err == 1)
{
ProcessSerialNumber mysn = {0, 0};
EventRecord event;
mysn.lowLongOfPSN = kSystemProcess;
SetFrontProcess(&mysn);
WaitNextEvent(0x0, &event, 60, NULL);
mysn.lowLongOfPSN = kCurrentProcess;
SetFrontProcess(&mysn);
}
return *err;
}
long readpipe(int fd, char *readbuffer, long size)
{
OSErr err;
PPCReadPBRec thedata;
thedata.sessRefNum = crt_fd_tab[fd].fd;
thedata.ioCompletion = 0;
thedata.bufferLength = size;
thedata.bufferPtr = readbuffer;
err = PPCReadAsync(&thedata);
err = waitforcompletion(&thedata.ioResult);
return thedata.actualLength;
}
long writepipe(int fd, char *writebuffer, long size)
{
OSErr err;
PPCWritePBRec thedata;
thedata.sessRefNum = crt_fd_tab[fd].fd;
thedata.ioCompletion = 0;
thedata.bufferLength = size;
thedata.bufferPtr = writebuffer;
thedata.more = 0;
thedata.userData = 0;
thedata.blockCreator = '????';
thedata.blockType = '????';
err = PPCWriteAsync(&thedata);
err = waitforcompletion(&thedata.ioResult);
return thedata.actualLength;
}